<?php
require_once '../config.php';
require_once '../dao/dao_db.php';
require_once '../dao/dao_weekly_report.php';
session_start();
session_cache_limiter('private');
if($_POST['reporttitle']!=''){
	$reporttitle=$_POST['reporttitle'];
}else{
	$reporttitle='';
}
if(isset($_POST['comment'])){
	$comment=$_POST['comment'];
	$titleid=$_POST['titleid'];
}

$reportcontent=$_POST['reportcontent'];
if(isset($_SESSION['userid'])&&trim($reportcontent)!=''&&$_SESSION['level']==STUDENT){
	$reportdate=date("Y-m-d");
	$result=save_report($reporttitle,$reportcontent,$reportdate,$_SESSION['userid']);
	mysql_close();
	if(mysql_num_rows($result)!=0){
		$row=mysql_fetch_array($result);
		$titleid=$row['Id'];
	}
	header("LOCATION:../list_weekly_report.php");
}else if($comment!=''&&$_SESSION['level']==TEACHER){
	save_comment($titleid,$comment);
	mysql_close();
	header("LOCATION:../view_weekly_report.php?id=$titleid");
}
else{
	header("LOCATION:../login.php");
}
?>